import MainHeader from '@/views/MainHeader.vue'
import loginView from "@/views/LoginView.vue";

export default {
    components: {MainHeader},

    methods: {
        //调用医生搜索接口
        loadDocker() {
            //整合条件
            const search = {
                "searchInput": this.search.searchInput,
                "departmentId": this.search.departmentId + "",
                "diseaseList.dIndex": this.search.diseaseFirst,
                "positionId": this.search.positionId + "",
            }
            const map = {
                'current': this.search.current,
                'size': this.search.size,
                'search': JSON.stringify(search),
                'sort': JSON.stringify(this.search.sort),
            }
            console.log('搜索条件：', map)
            //发送请求
            this.$axios.post('/search/docker', map)
                .then(res => {
                    console.log('返回的医生集合：', res.data);
                    this.page.total = res.data.total;
                    this.dockerList = res.data.data;
                }).catch();
        },

        //搜索类型切换change方法
        searchTypeChange() {
            switch (this.search.searchType) {
                case '全部':
                    this.search.pDepartmentId = 1;
                    this.search.departmentId = '';
                    this.search.diseaseFirst = '';
                    break;
                case '科室':
                    this.search.diseaseFirst = '';
                    break;
                case '疾病':
                    this.search.pDepartmentId = 1;
                    this.search.departmentId = '';
                    break;
            }
            this.loadDocker();
        },

        //排序图标变化
        sortIconChange(buttonName) {
            switch (buttonName) {
                case 'null':
                    this.sortIcon.scoreIcon = this.sortIcon.right;
                    this.sortIcon.positionIcon = this.sortIcon.right;
                    this.search.sort.field = "";
                    this.search.sort.type = "";
                    break;
                case 'position':
                    this.sortIcon.scoreIcon = this.sortIcon.right;
                    this.search.sort.field = "positionId";
                    switch (this.sortIcon.positionIcon) {
                        case this.sortIcon.right:
                            this.sortIcon.positionIcon = this.sortIcon.down;
                            this.search.sort.type = "ASC";
                            break;
                        case this.sortIcon.down:
                            this.sortIcon.positionIcon = this.sortIcon.up;
                            this.search.sort.type = "DESC";
                            break;
                        case this.sortIcon.up:
                            this.sortIcon.positionIcon = this.sortIcon.right;
                            this.search.sort.type = "";
                            break;
                    }
                    break;
                case 'score':
                    this.sortIcon.positionIcon = this.sortIcon.right;
                    this.search.sort.field = "score";
                    switch (this.sortIcon.scoreIcon) {
                        case this.sortIcon.right:
                            this.sortIcon.scoreIcon = this.sortIcon.down;
                            this.search.sort.type = "DESC";
                            break;
                        case this.sortIcon.down:
                            this.sortIcon.scoreIcon = this.sortIcon.up;
                            this.search.sort.type = "ASC";
                            break;
                        case this.sortIcon.up:
                            this.sortIcon.scoreIcon = this.sortIcon.right;
                            this.search.sort.type = "";
                            break;
                    }
                    break;
            }
            this.loadDocker();
        },

        //每页条数变动事件
        sizeChange(val) {
            this.search.size = val;
            this.loadDocker();
        }, //页码变动事件
        currentChange(val) {
            this.search.current = val;
            this.loadDocker();
        },

        //查所有科室
        getAllDepartmentList() {
            this.$axios.get('/search/all-department')
                .then(res => {
                    const departmentList = res.data;
                    this.departmentList = departmentList;
                    console.log('所有科室列表：', departmentList);
                }).catch();
        },

        //查所有医生职位
        getAllPosition() {
            this.$axios.get('/search/all-position')
                .then(res => {
                    this.positionList = res.data;
                    console.log("职位集合：", this.positionList);
                }).catch()
        },

        //跳转方法
        routerLink(id, positionId) {
            this.$router.push({
                path: '/doctor', query: {
                    'doctorId': id,
                    'positionId': positionId
                }
            })
            console.log("id:",id)
        },
    },

    mounted() {
        this.getAllDepartmentList();
        this.getAllPosition();
        this.loadDocker();
    },

    data() {
        return {
            search: {
                current: 1, size: 20, searchInput: '',     /*搜索输入框*/
                searchType: '全部',   /*搜索类型*/
                pDepartmentId: 1,    /*一级科室id*/
                departmentId: '',    /*科室id*/
                diseaseFirst: '',    /*擅长疾病首字母拼音*/
                positionId: '',      /*职位id*/
                sort: {
                    field: '', type: '',
                },/*排序类型*/
            },
            page: {
                total: 0,
            },               /*分页*/
            dockerList: [],        /*医生集合*/
            departmentList: [],    /*科室集合*/
            positionList: [],      /*医生职位集合*/
            sortIcon: {
                scoreIcon: 'el-icon-arrow-right',      /*评分排序图标*/
                positionIcon: 'el-icon-arrow-right',   /*职位排序图标*/
                down: "el-icon-arrow-down", up: "el-icon-arrow-up", right: "el-icon-arrow-right"
            },
            AZ: ['A', 'B', 'C', 'D', "E", 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],             /*字母数组*/
            position: {
                id: '', pname: ''
            },
        }
    }
}
